﻿using System;
using System.Collections.Generic;
using Battle.Engine.InputData;
using Dict.Config;

namespace Battle.Engine.LogicModel
{
    public class FStateManager
    {
        public List<string> immuneTalentGroup; // 免疫天赋组
        public List<string> immuneBuffGroup; // 免疫buff组

        public int invisibleNumber; // 隐身    
        public int invincibleNumber; // 无敌      
        public int mustHitNumber; // 必中      
        public int mustCriNumber; // 必暴
        public int dizzyNumber; // 眩晕
        public int fireNumber; // 火
        public int poisonNumber; // 毒
        public int iceNumber; // 冰
        public int forbidFirstSkillNumber; // 禁止释放小招1
        public int forbidSecondSkillNumber; //禁止释放小招2
        public int forbidUltimateSkillNumber; //禁止释放大招
        public int forbidAddSkillAngerNumber; //禁止技能增加怒气  
        public int forbidAddHpNumber; // 禁止回血
        public int immuneDefNumber; // 无视防御和伤害减免，造成真实伤害
        public int immuneDizzyNumber; // 免疫眩晕
        public int immuneDebuffNumber;  // 免疫Debuff
        public int immuneFloatBreakNumber;  // 免疫浮空倒地状态
        public int canNotKillNumber; //无法击杀目标
        public int dieAfterLastAttackNumber;//血量为0不死，在自己回合结束后才死亡
        public int uneffectBuffOnceNumber;  // buff暂时不生效
        public int sameDamForRandomNumber;  //除目标以外随机一人受同等伤害


        public bool IsInvisible;
        public bool IsInvincible;
        public bool IsMustHit;
        public bool IsMustCri;
        public bool IsDizzy;
        public bool IsFire;
        public bool IsPoison;
        public bool IsIce;
        public bool isForbidFirstSkill;
        public bool IsForbidSecondSkill;
        public bool IsForbidUltimateSkill;
        public bool IsForbidAddSkillAnger;
        public bool IsForbidAddHp;
        public bool IsImmuneDef;
        public bool IsImmuneDizzy;
        public bool IsImmuneDebuff;
        public bool IsImmuneFloatBreak;
        public bool IsCanNotKill;
        public bool IsDieAfterLastAttack;
        public bool IsUneffectBuffOnce;  // buff暂时不生效
        public bool IsSameDamForRandom;


        public FStateManager(FActor actor)
        {
            this.immuneTalentGroup = new List<string>();
            this.immuneBuffGroup = new List<string>();
            clear();
        }

        public bool IsImmuneTalentGroup(string talentGroup)
        {
            if (immuneTalentGroup.Contains(talentGroup))
            {
                return true;
            }
            return false;
        }

        public bool IsImmuneBuffGroup(string buffGroup)
        {
            if (immuneBuffGroup.Contains(buffGroup))
            {
                return true;
            }
            return false;
        }

        public bool IsImmuneBuff(Buff buff)
        {
            if(buff.isDebuff && this.IsImmuneDebuff)
            {
                return true;
            }
            if (buff.factor.Equals(TableFactorConst.dizzy) && this.IsImmuneDizzy)
            {
                return true;
            }
            return false;
        }

        public void AddStateNumByType(Buff buff, string type, int num)
        {
            switch (type)
            {
                case TableFactorConst.invisible:
                    this.invisibleNumber+=num;
                    if (this.invisibleNumber > 0)
                    {
                        this.IsInvisible = true;
                    }
                    else
                    {
                        this.IsInvisible = false;
                    }
                    break;
                case TableFactorConst.invincible:
                    this.invincibleNumber+=num;
                    if (this.invincibleNumber > 0)
                    {
                        this.IsInvincible = true;
                    }
                    else
                    {
                        this.IsInvincible = false;
                    }
                    break;
                case TableFactorConst.mustHit:
                    this.mustHitNumber+=num;
                    if (this.mustHitNumber > 0)
                    {
                        this.IsMustHit = true;
                    }
                    else
                    {
                        this.IsMustHit = false;
                    }
                    break;
                case TableFactorConst.mustCri:
                    this.mustCriNumber+=num;
                    if (this.mustCriNumber > 0)
                    {
                        this.IsMustCri = true;
                    }
                    else
                    {
                        this.IsMustCri = false;
                    }
                    break;
                case TableFactorConst.dizzy:
                    this.dizzyNumber+=num;
                    if (this.dizzyNumber > 0)
                    {
                        this.IsDizzy = true;
                    }
                    else
                    {
                        this.IsDizzy = false;
                    }
                    break;
                case TableFactorConst.fireDam:
                    this.fireNumber += num;
                    if (this.fireNumber > 0)
                    {
                        this.IsFire = true;
                    }
                    else
                    {
                        this.IsFire = false;
                    }
                    break;
                case TableFactorConst.poisonDam:
                    this.poisonNumber += num;
                    if (this.poisonNumber > 0)
                    {
                        this.IsPoison = true;
                    }
                    else
                    {
                        this.IsPoison = false;
                    }
                    break;
                case TableFactorConst.ice:
                    this.iceNumber += num;
                    if (this.iceNumber > 0)
                    {
                        this.IsIce = true;
                    }
                    else
                    {
                        this.IsIce = false;
                    }
                    break;
                case TableFactorConst.forbidFirstSkill:
                    this.forbidFirstSkillNumber+=num;
                    if (this.forbidFirstSkillNumber > 0)
                    {
                        this.isForbidFirstSkill = true;
                    }
                    else
                    {
                        this.isForbidFirstSkill = false;
                    }
                    break;
                case TableFactorConst.forbidSecondSkill:
                    this.forbidSecondSkillNumber+=num;
                    if (this.forbidSecondSkillNumber > 0)
                    {
                        this.IsForbidSecondSkill = true;
                    }
                    else
                    {
                        this.IsForbidSecondSkill = false;
                    }
                    break;
                case TableFactorConst.forbidUltimateSkill:
                    this.forbidUltimateSkillNumber+=num;
                    if (this.forbidUltimateSkillNumber > 0)
                    {
                        this.IsForbidUltimateSkill = true;
                    }
                    else
                    {
                        this.IsForbidUltimateSkill = false;
                    }
                    break;
                case TableFactorConst.forbidAddSkillAnger:
                    this.forbidAddSkillAngerNumber+=num;
                    if (this.forbidAddSkillAngerNumber > 0)
                    {
                        this.IsForbidAddSkillAnger = true;
                    }
                    else
                    {
                        this.IsForbidAddSkillAnger = false;
                    }
                    break;
                case TableFactorConst.forbidAddHp:
                    this.forbidAddHpNumber+=num;
                    if (this.forbidAddHpNumber > 0)
                    {
                        this.IsForbidAddHp = true;
                    }
                    else
                    {
                        this.IsForbidAddHp = false;
                    }
                    break;
                case TableFactorConst.immuneDef:
                    this.immuneDefNumber += num;
                    if (this.immuneDefNumber > 0)
                    {
                        this.IsImmuneDef = true;
                    }
                    else
                    {
                        this.IsImmuneDef = false;
                    }
                    break;
                case TableFactorConst.immuneDizzy:
                    this.immuneDizzyNumber += num;
                    if (this.immuneDizzyNumber > 0)
                    {
                        this.IsImmuneDizzy = true;
                    }
                    else
                    {
                        this.IsImmuneDizzy = false;
                    }
                    break;
                case TableFactorConst.immuneDebuff:
                    this.immuneDebuffNumber += num;
                    if (this.immuneDebuffNumber > 0)
                    {
                        this.IsImmuneDebuff = true;
                    }
                    else
                    {
                        this.IsImmuneDebuff = false;
                    }
                    break;
                case TableFactorConst.immuneFloatBreak:
                    this.immuneFloatBreakNumber += num;
                    if (this.immuneFloatBreakNumber > 0)
                    {
                        this.IsImmuneFloatBreak = true;
                    }
                    else
                    {
                        this.IsImmuneFloatBreak = false;
                    }
                    break;
                case TableFactorConst.canNotKill:
                    this.canNotKillNumber += num;
                    if (this.canNotKillNumber > 0)
                    {
                        this.IsCanNotKill = true;
                    }
                    else
                    {
                        this.IsCanNotKill = false;
                    }
                    break;
                case TableFactorConst.dieAfterLastAttack:
                    this.dieAfterLastAttackNumber += num;
                    if (this.dieAfterLastAttackNumber > 0)
                    {
                        this.IsDieAfterLastAttack = true;
                    }
                    else
                    {
                        this.IsDieAfterLastAttack = false;
                    }
                    break;
                case TableFactorConst.uneffectBuffOnce:
                    this.uneffectBuffOnceNumber += num;
                    if (this.uneffectBuffOnceNumber > 0)
                    {
                        this.IsUneffectBuffOnce = true;
                    }
                    else
                    {
                        this.IsUneffectBuffOnce = false;
                    }
                    break;
                case TableFactorConst.sameDamForRandom:
                    this.sameDamForRandomNumber += num;
                    if (this.sameDamForRandomNumber > 0)
                    {
                        this.IsSameDamForRandom = true;
                    }
                    else
                    {
                        this.IsSameDamForRandom = false;
                    }
                    break;
                default:
                    //未处理的状态类型
                    Debug.LogError("FStateManager AddStateNumByType--->Unknown type:" + type);
                    break;
            }
        }

        
        public void clear()
        {
            this.invisibleNumber = 0; // 隐身    
            this.invincibleNumber = 0; // 无敌      
            this.mustHitNumber = 0; // 必中      
            this.mustCriNumber = 0; // 必暴
            this.dizzyNumber = 0; // 眩晕
            this.fireNumber = 0;// 火
            this.poisonNumber = 0;// 毒
            this.iceNumber = 0;// 冰
            this.forbidFirstSkillNumber = 0; // 禁止释放小招1
            this.forbidSecondSkillNumber = 0; //禁止释放小招2
            this.forbidUltimateSkillNumber = 0; //禁止释放大招
            this.forbidAddSkillAngerNumber = 0; //禁止技能增加怒气  
            this.forbidAddHpNumber = 0; // 禁止回血
            this.immuneDefNumber = 0; // 无视防御和伤害减免，造成真实伤害
            this.immuneDizzyNumber = 0;// 免疫眩晕
            this.immuneDebuffNumber = 0;  // 免疫Debuff
            this.immuneFloatBreakNumber = 0;  // 免疫浮空倒地状态
            this.canNotKillNumber = 0;//无法击杀目标
            this.dieAfterLastAttackNumber = 0; //血量为0不死
            this.uneffectBuffOnceNumber = 0; //buff暂时不生效
            this.sameDamForRandomNumber = 0;
            
            this.IsInvisible = false;
            this.IsInvincible = false;
            this.IsMustHit = false;
            this.IsMustCri = false;
            this.IsDizzy = false;
            this.IsFire = false;
            this.IsPoison = false;
            this.IsIce = false;
            this.isForbidFirstSkill = false;
            this.IsForbidSecondSkill = false;
            this.IsForbidUltimateSkill = false;
            this.IsForbidAddSkillAnger = false;
            this.IsForbidAddHp = false;
            this.IsImmuneDef = false;
            this.IsImmuneDizzy = false;
            this.IsImmuneDebuff = false;
            this.IsImmuneFloatBreak = false;
            this.IsCanNotKill = false;
            this.IsDieAfterLastAttack = false;
            this.IsUneffectBuffOnce = false;
            this.IsSameDamForRandom = false;
        }
    }
}
